import { loadEnv, mergeConfig } from 'vite';
import eslint from 'vite-plugin-eslint';
import baseConfig from './vite.config.base';

export default mergeConfig(
  {
    mode: 'development',
    server: {
      open: true,
      fs: {
        strict: true,
      },
      proxy: {
        '/auth': {
          target: loadEnv('development', '.').VITE_PROXY,
          rewrite: (path: string) => path.replace(/^\/auth/, '/auth'),
          configure: (server) =>
            // 拦截请求 打印地址。方便辨认重定向后的地址是否正确 没有端口信息
            server.on('proxyReq', (req: any) =>
              console.log(`${req.host}${req.path}`)
            ),
        },
        '/upms': {
          target: loadEnv('development', '.').VITE_PROXY,
          rewrite: (path: string) => path.replace(/^\/upms/, '/upms'),
          configure: (server) =>
            // 拦截请求 打印地址。方便辨认重定向后的地址是否正确 没有端口信息
            server.on('proxyReq', (req: any) =>
              console.log(`${req.host}${req.path}`)
            ),
        },
        '/mall': {
          target: loadEnv('development', '.').VITE_PROXY,
          rewrite: (path: string) => path.replace(/^\/mall/, '/mall'),
          configure: (server) =>
            // 拦截请求 打印地址。方便辨认重定向后的地址是否正确 没有端口信息
            server.on('proxyReq', (req: any) =>
              console.log(`${req.host}${req.path}`)
            ),
        },
      },
    },
    plugins: [
      eslint({
        cache: false,
        include: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.vue'],
        exclude: ['node_modules'],
      }),
    ],
  },
  baseConfig
);
